﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Seagull.Model
{
    // TODO: Change to struct and represent all channel instead of byte
    public static class Channel
    {
        public const byte PhaseChannel = 0;

        public const byte MinChannel = 1;

        public const byte UnknownChannel = 0xfe;

        public static byte MaxChannel(int channelCount)
        {
            return (byte)(MinChannel + channelCount - 1);
        }

        public static void ForAllChannels(int channelCount, Action<byte> actionOnChannel)
        {
            var maxChannel = MaxChannel(channelCount);
            for(byte channel = MinChannel; channel <= maxChannel; channel++)
            {
                actionOnChannel(channel);
            }
        }

        public static bool IsValidChannel(byte channel, int channelCount)
        {
            return channel >= MinChannel && channel <= MaxChannel(channelCount);
        }

        public static string GetChannelName(byte channel)
        {
            return channel == PhaseChannel ? "相位通道" : "通道" + channel;
        }
    }
}
